﻿using Collections.Pooled;
using furion.blog.Domain.Shared.Attribute;
using furion.blog.Domain.Shared.Vo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace furion.blog.Domain.Shared.Enum
{
    /// <summary>
    /// 请求微信接口枚举
    /// </summary>
    public enum WxRequestApiEnum
    {
        [EnumAttribute(Name = "小程序Code2Session", Desc = "小程序通过code获取用户openid", Value = "MiniProgramCode2Session")]
        MiniProgramCode2Session,

        [EnumAttribute(Name = "小程序发送信息给会员", Desc = "小程序给会员发送消息", Value = "MiniProgramSendMessageToCustomer")]
        MiniProgramSendMessageToCustomer,

        [EnumAttribute(Name = "小程序AccessToken", Desc = "小程序获取AccessToken", Value = "MiniProgramAccessToken")]
        MiniProgramAccessToken,
    }

    public class WxRequestApi
    {
        public static async Task<PooledSet<NameValueVO>> Items()
        {
            return await Task.Run(() =>
            {
                PooledSet<NameValueVO> ret = new PooledSet<NameValueVO>();
                Type t = typeof(WxRequestApiEnum);
                FieldInfo fd = null;
                foreach (var name in t.GetEnumNames())
                {
                    fd = t.GetField(name);
                    var attr = fd.GetCustomAttribute(typeof(EnumAttribute), false) as EnumAttribute;
                    ret.Add(new NameValueVO { Name = attr.Name, Value = attr.Value });
                }
                return ret;
            });
        }
    }

}
